﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Quexcel.OpenXML.Transaction
{
    /**
     * A spererate class is created for the trasaction manager, instead of putting the dictionary object in the
     * ExcelConnection because the Transaction can be made to use run in a seperate threads in the future */
    internal class TransactionManager
    {
        Dictionary<long, ExcelTransaction> transactionList;

        internal TransactionManager()
        {
            transactionList = new Dictionary<long, ExcelTransaction>();
        }

        internal long Add(ExcelTransaction transaction)
        {
            long tId = DateTime.Now.Ticks;
            transactionList.Add(tId, transaction);

            return tId;
        }

        internal void CloseAll()
        {
            foreach (ExcelTransaction transaction in transactionList.Values)
            {
                transaction.Dispose();
            }
        }
    }
}
